package com.ruoyi.web.controller.datastatistics;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedata.domain.RealtimegatherdataXbView;
import com.ruoyi.basedata.service.IRealtimegatherdataXbViewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小表实时数据视图Controller
 *
 * @author gdqt
 * @date 2024-03-18
 */
@RestController
@RequestMapping("/basedata/realtimegatherdataXbView")
public class RealtimegatherdataXbViewController extends BaseController {
    @Autowired
    private IRealtimegatherdataXbViewService realtimegatherdataXbViewService;

    /**
     * 查询小表实时数据视图列表
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdataxb:list')")
    @GetMapping("/list")
    public TableDataInfo list(RealtimegatherdataXbView realtimegatherdataXbView) {
        startPage();
        List<RealtimegatherdataXbView> list = realtimegatherdataXbViewService.selectRealtimegatherdataXbViewList(realtimegatherdataXbView);
        return getDataTable(list);
    }

    /**
     * 导出小表实时数据视图列表
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdataxb:export')")
    @Log(title = "小表实时数据视图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RealtimegatherdataXbView realtimegatherdataXbView) {
        List<RealtimegatherdataXbView> list = realtimegatherdataXbViewService.selectRealtimegatherdataXbViewList(realtimegatherdataXbView);
        list.forEach(item -> {
            if (item.getTenantId().equals("710712")) {
                String totalFlowStr = item.getTotalFlow().toString();
                if (totalFlowStr.contains(".")) {
                    item.setTotalFlowStr(totalFlowStr.substring(0, totalFlowStr.indexOf(".")));
                }
            } else {
                item.setTotalFlowStr(item.getTotalFlow().toString());
            }
        });
        ExcelUtil<RealtimegatherdataXbView> util = new ExcelUtil<RealtimegatherdataXbView>(RealtimegatherdataXbView.class);
        util.exportExcel(response, list, "小表实时数据视图数据");
    }

    /**
     * 获取小表实时数据视图详细信息
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdataxb:query')")
    @GetMapping(value = "/{tenantId}")
    public AjaxResult getInfo(@PathVariable("tenantId") String tenantId) {
        return success(realtimegatherdataXbViewService.selectRealtimegatherdataXbViewByTenantId(tenantId));
    }

    /**
     * 新增小表实时数据视图
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdataxb:add')")
    @Log(title = "小表实时数据视图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RealtimegatherdataXbView realtimegatherdataXbView) {
        return toAjax(realtimegatherdataXbViewService.insertRealtimegatherdataXbView(realtimegatherdataXbView));
    }

    /**
     * 修改小表实时数据视图
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdataxb:edit')")
    @Log(title = "小表实时数据视图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RealtimegatherdataXbView realtimegatherdataXbView) {
        return toAjax(realtimegatherdataXbViewService.updateRealtimegatherdataXbView(realtimegatherdataXbView));
    }

    /**
     * 删除小表实时数据视图
     */
    @PreAuthorize("@ss.hasPermi('datastatistics:realtimegatherdataxb:remove')")
    @Log(title = "小表实时数据视图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tenantIds}")
    public AjaxResult remove(@PathVariable String[] tenantIds) {
        return toAjax(realtimegatherdataXbViewService.deleteRealtimegatherdataXbViewByTenantIds(tenantIds));
    }
}
